package com.example.dbmysql.Controller;

import com.example.dbmysql.pojo.Configuration;
import com.example.dbmysql.result.Result;
import com.example.dbmysql.service.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/configurationController")
public class configurationController {

    @Autowired
    private ConfigurationService configurationService;

    @GetMapping("/getMsg")
    public Result getMsg(){

        Configuration config =  configurationService.select();

        return Result.success(config);
    }

    @PostMapping("/Edit")
    public  Result edit(@RequestBody Configuration configuration){

        Configuration obj = configurationService.select();

        if(obj != null) {
            if(configuration.getCheckOutConfiguration() != 0){
                if(configuration.getTimeClean() <= 0){
                    return Result.error("请传入退房后多少分钟变干净房");
                }
            }
            configurationService.update(configuration);
        }else{
            configurationService.edit(configuration);
        }

        return Result.success();
    }

}
